<template>
  <div class="index-container">
    <vab-query-form>
      <vab-query-form-top-panel>
        <el-form
          ref="form"
          :inline="true"
          label-width="49px"
          :model="queryForm"
          @submit.native.prevent
        >
          <el-form-item label="门店">
            <el-select v-model="queryForm.storeid">
              <el-option
                v-for="item in storeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="员工">
            <el-select v-model="queryForm.staffid">
              <el-option
                v-for="item in staffOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              native-type="submit"
              type="primary"
              @click="handleQuery"
            >
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-top-panel>
    </vab-query-form>

    <el-table ref="tableSort" v-loading="listLoading" :data="list">
      <el-table-column
        align="center"
        label="ID"
        prop="id"
        show-overflow-tooltip
        width="55"
      />

      <el-table-column
        align="center"
        label="员工名称"
        prop="staffname"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="门店名称"
        prop="storename"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="服务态度"
        prop="attitude"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="服务质量"
        prop="quality"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="店内环境"
        prop="environment"
        show-overflow-tooltip
        width="200"
      />
      <el-table-column
        align="center"
        label="意见&建议"
        prop="feedback"
        show-overflow-tooltip
        width="200"
      />
      <el-table-column
        align="center"
        label="顾客姓名"
        prop="username"
        show-overflow-tooltip
        width="200"
      />
      <el-table-column
        align="center"
        label="顾客电话"
        prop="phone"
        show-overflow-tooltip
        width="200"
      />
      <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="85"
      >
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">详情</el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-image
          class="vab-data-empty"
          :src="require('@/assets/empty_images/data_empty.png')"
        />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.page"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <table-edit ref="edit" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { getList, getStore, getUserList } from '@/api/evaluate'
  import TableEdit from './components/TableEdit'
  export default {
    name: 'Index',
    components: {
      TableEdit,
    },
    data() {
      return {
        list: [],
        imageList: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          storeid: 0,
          staffid: 0,
          page: 1,
          pageSize: 10,
        },

        storeOptions: [{ id: 0, name: '全部' }],
        staffOptions: [{ value: 0, label: '全部' }],
      }
    },
    created() {
      this.fetchData()
      this.storeData()
      this.staffData()
    },
    methods: {
      handleEdit(row) {
        this.$refs['edit'].showEdit(row)
      },

      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.page = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const {
          data: { list, total },
        } = await getList(this.queryForm)
        this.list = list
        this.total = total
        this.listLoading = false
      },

      async storeData() {
        const data = await getStore()
        this.storeOptions = [...this.storeOptions, ...data.data]
      },

      async staffData() {
        const data = await getUserList()
        this.staffOptions = [...this.staffOptions, ...data.data]
      },
    },
  }
</script>

<style lang="scss" scoped></style>
